package com.devshephard.rpcframework.rpc.monitor.impl;

import com.devshephard.rpcframework.rpc.monitor.RpcMonitor;
import javax.servlet.http.HttpServletResponse;
import java.util.concurrent.ConcurrentHashMap;

public class RpcMonitorImpl implements RpcMonitor {

    private volatile ConcurrentHashMap RequestConcurrentHashMap;

    @Override
    public ConcurrentHashMap getConcurrentHashMap() {
        return this.RequestConcurrentHashMap;
    }

    @Override
    public Boolean setResponse(HttpServletResponse httpServletResponse) {

        String ResponseId = String.valueOf(httpServletResponse.hashCode());

        try{

            synchronized (this){
                RequestConcurrentHashMap.put(ResponseId, httpServletResponse);
            }

        }catch (Exception e){
            e.printStackTrace();
            return false;
        }

        return true;
    }

    @Override
    public HttpServletResponse getResponse(String ResponseId) {
        return (HttpServletResponse) RequestConcurrentHashMap.get(ResponseId);
    }



}
